'use strict'

const fs = require('fs');
const path = require('path');
const { sequelize } = require('../db');

// 过滤文件夹中的文件
var fn_filterFile = function () {
var currentDirAllFile = fs.readdirSync(__dirname);
var currentFile = path.basename(__filename);
return currentDirAllFile.filter(fileName => {
    return fileName.endsWith('.js') && fileName !== currentFile;
});
};


//注册过滤好的文件

var fn_registerFile = function(filterFile){
    var obj = {};
    filterFile.forEach(name =>{
        var modelName = name.substring(0,name.length-3);
        obj[modelName] = require(path.join(__dirname,name));
    });
    return obj;
};



var filterFile = fn_filterFile();
var obj = fn_registerFile(filterFile);

obj.sync = async ()=>{
    return sequelize.sync({force: true});
}


module.exports = obj;